package cn.wolfcode.ssm.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;

@Getter
@Setter
public class CourseOrder {
    private Long id;

    // 录入时间
    private Date inputTime;

    // 购买对象
    private Customer customer;

    // 购买课程
    private SystemDictionaryItem course;

    // 价格
    private BigDecimal money;


    public String getJson() {
        // new一个map 把数值装进去
        HashMap<Object,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("inputTime",inputTime);
        map.put("money",money);
        if (course != null){
            map.put("course_id",course.getId());
            map.put("course_title",course.getTitle());
        }
        if (customer != null){
            map.put("customer_id",customer.getId());
            map.put("customer_name",customer.getName());
        }

        // 这里返回一个json格式的字符串
        return JSON.toJSONString(map);
    }


}